<template>
	<!-- 查看报告时判断是不是厂区会员  如果是有权限可以查看没有权限不能查看
	 如果是普通会员   查看需要缴费   跳转页面写入查看报告的好处-->
	<view class="mine-container">
		<u-navbar :is-back="false" :placeholder="true" title="我的"></u-navbar>
		<view class="bg" :style="{ height: bgHeight }"></view>
		<scroll-view class="scrollWrap" :style="{ height: domHeight }" :enhanced="true" scroll-y :bounces="false" :show-scrollbar="false">
			<view class="header-section">
				<view class="bg-wrap">
					<view class="head-img" @click="goInfo">
						<view>
							<image :src="form.avatar"></image>
							<view>
								<image src="/static/images/edit.svg"></image>
							</view>
						</view>
						<view v-if="form.nickName">{{ form.nickName }}</view>
						<view v-if="!form.nickName"></view>
					</view>
					<view class="operate-list">
						<!-- <view @click="handleAppointOrder">
							<div class="icons">
								<image src="/static/images/yuyue.svg" style="width: 51rpx; height: 60rpx; margin-top: 8rpx"></image>
							</div>
							<div class="titles">预约订单</div>
						</view> -->
						<view class="contact">
							<button open-type="contact" @contact="handleContact">
								<div class="icons"><image src="/static/images/kefu.svg" style="width: 55rpx; height: 60rpx; margin-top: 7rpx"></image></div>

								<div class="titles">客服中心</div>
							</button>
						</view>
						<view @click="handelMyEvaluate">
							<div class="icons"><image src="/static/images/ceping.svg" style="width: 50rpx; height: 60rpx; margin-top: 10rpx; margin-left: 8rpx"></image></div>

							<div class="titles">我的测评</div>
						</view>
						<view @click="goSugget">
							<div class="icons"><image src="/static/images/yj.svg" style="width: 51rpx; height: 55rpx; margin-top: 15rpx"></image></div>
							<div class="titles">意见反馈</div>
						</view>
					</view>
				</view>
			</view>
			<view class="content-section">
				<view class="content-section-list">
					<view @click="userDetail">
						<image src="/static/images/userDetail.svg"></image>
						<text>用户协议</text>
					</view>
					<view @click="private">
						<image src="/static/images/private.svg"></image>
						<text>隐私政策</text>
					</view>
				</view>
			</view>
			<view @click="goPhone" class="footer">
				<view>
					<image src="/static/images/phone.svg"></image>
				</view>

				<view>{{ data }}</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getInfos } from '@/api/system/user';
import { createOrder, createRefund } from '@/api/weiPay/index';
import { getconfiguration } from '@/api/config/index.js';
export default {
	data() {
		return {
			data: '',
			name: this.$store.state.user.name,
			form: {},
			domHeight: '',
			bgHeight: ''
		};
	},
	computed: {
		avatar() {
			return this.$store.state.user.avatar;
		},
		windowHeight() {
			return uni.getSystemInfoSync().windowHeight - 50;
		}
	},
	onShareAppMessage() {
		return {
			title: '仰望心理'
			// ...其他配置
		};
	},
	onShow() {
		let userId = uni.getStorageSync('user_id');
		getInfos(userId).then((res) => {
			this.form = res.data;
		});
		getconfiguration({
			categoryName: '心理热线'
		}).then((res) => {
			this.data = res.data.configuration;
		});
	},
	methods: {
		userDetail() {
			this.$tab.navigateTo('/subset/pages/setting/agreement');
		},
		private() {
			this.$tab.navigateTo('/subset/pages/setting/policy');
		},
		goPhone() {
			// 判断手机是否支持拨打电话功能
			if (uni.canIUse('makePhoneCall')) {
				uni.makePhoneCall({
					phoneNumber: this.data, // 电话号码
					success: function () {},
					fail: function () {
						console.log('拨打电话失败');
					}
				});
			} else {
				console.log('你的设备不支持拨打电话功能');
			}
		},

		handleContact(e) {
			console.log('客服会话触发', e.detail); // 包含sessionFrom等参数
			// 可在此处记录用户行为或上报数据
		},
		handleAppointOrder() {
			this.$tab.navigateTo(`/subset/pages/consult/search/myConsult`);
		},
		handelMyEvaluate() {
			this.$tab.navigateTo(`/subset/pages/evaluate/search/myEvaluate`);
		},
		handelMyAtten() {
			this.$tab.navigateTo(`/subset/pages/consult/search/myAttent`);
		},
		backPay() {
			createRefund().then((res) => {});
		},
		goPay() {
			createOrder({
				description: '测试描述',
				outTradeNo: '989567234562111',
				totalFee: 1,
				wxOpenId: this.form.openId
			}).then((res) => {
				uni.requestPayment({
					timeStamp: res.data.timeStamp,
					nonceStr: res.data.nonceStr,
					package: res.data.packageVal,
					signType: res.data.signType,
					paySign: res.data.paySign,
					success: function (res) {
						console.log(res, 'success');
					},
					fail: function (res) {
						console.log(res, 'file');
					},
					complete: function (res) {
						console.log(res, 'complete');
					}
				});
			});
		},
		goInfo() {
			this.$tab.navigateTo(`/subset/pages/info/index`);
			// this.$tab.navigateTo(`/subset/pages/personInfo/personInfo`);
		},
		goSetting() {
			this.$tab.navigateTo(`/subset/pages/setting/index`);
		},
		goSugget() {
			this.$tab.navigateTo(`/subset/pages/suggest/index`);
		},
		onGetPhoneNumber(e) {
			if (e.detail.errMsg === 'getPhoneNumber:ok') {
				// 获取到加密数据和iv
				const { encryptedData, iv } = e.detail;
				console.log(e.detail);
				// 将加密数据和iv发送到你的服务器进行解密
				// uni.request({
				// 	url: 'https://your-server-domain.com/api/decrypt-phone', // 替换为你的服务器接口
				// 	method: 'POST',
				// 	data: {
				// 		encryptedData: encryptedData,
				// 		iv: iv
				// 	},
				// 	success: (response) => {
				// 		console.log('解密成功:', response.data);
				// 		// 在这里处理解密成功的逻辑，比如保存用户手机号到本地
				// 		uni.setStorageSync('userPhone', response.data.phoneNumber);
				// 	},
				// 	fail: (error) => {
				// 		console.error('解密失败:', error);
				// 	}
				// });
			} else {
				console.error('用户拒绝授权获取手机号');
			}
		},
		handleToInfo() {
			// this.$tab.navigateTo('/pages/mine/info/index')
		},
		handleToEditInfo() {
			// this.$tab.navigateTo('/pages/mine/info/edit')
		},
		handleToSetting() {
			// this.$tab.navigateTo('/pages/mine/setting/index')
		},
		handleToLogin() {
			// this.$tab.reLaunch('/pages/login')
			uni.login({
				success: (res) => {
					// console.log(res);
					this.$store
						.dispatch('Login', {
							code: res.code,
							publicOpenId: '',
							shareUserId: 0,
							userInfo: {
								age: '',
								avatarUrl: '',
								education: '',
								enterpriseDeptName: '',
								enterpriseName: '',
								factoryName: '',
								language: '',
								maritalStatus: '',
								medicalHistoryDescribe: '',
								medicalHistoryStatus: '',
								nickName: '',
								occupation: '',
								phone: '',
								sex: '',
								userId: 0
							}
						})
						.then(() => {
							this.$modal.closeLoading();
							this.loginSuccess();
						})
						.catch(() => {
							if (this.captchaEnabled) {
								this.getCode();
							}
						});
				}
			});
		},
		// 登录成功后，处理函数
		loginSuccess(result) {
			// 设置用户信息
			this.$store.dispatch('GetInfo').then((res) => {
				this.$tab.reLaunch('/pages/index');
			});
		}
	},
	mounted() {
		this.domHeight = uni.getStorageSync('domHeight');
		this.bgHeight = `calc(100% - ${this.domHeight} + 472rpx)`;
		// console.log(this.domHeight);
	}
};
</script>

<style lang="scss" scoped>
@import url('@/static/font/navBar.less');
.footer {
	position: fixed;
	bottom: 200rpx;
	left: calc((100% - 280rpx) / 2);
	width: 280rpx;
	display: flex;
	align-items: center;
	height: 50rpx;
	line-height: 50rpx;
	text-align: center;
	margin: auto;
	> view:first-child {
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
		image {
			width: 40rpx;
			height: 40rpx;
		}
	}
	> view:last-child {
		color: #666;
		font-size: 32rpx;
	}
}
.mine-container {
	width: 100%;
	height: 100%;
	background-color: #f5f4f8;
	overflow: hidden;
	height: 100%;
	position: relative;
	background-color: #f6f7ff;
	.bg {
		position: fixed;
		top: 0;
		width: 750rpx;
		height: 472rpx;
		background: linear-gradient(10deg, rgba(93, 206, 88, 0) 0%, #9ed35a 12%, #fffa76 39%, #e3da56 51%, #89d15b 96%, #dcffd9 100%);
		border-radius: 0px;
		opacity: 0.29;
	}
	.scrollWrap {
		width: 100%;
		padding-bottom: 20rpx;
	}
	.header-section {
		width: 100%;
		height: 600rpx;
		position: relative;
		// background: linear-gradient(127deg, #a4dcb3 0%, #ffeed6 37%, #d3fffb 100%);
		.bg {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			top: 0;
		}
		.bg-wrap {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			top: 0;
			.head-img {
				width: 100%;
				padding: 72rpx 0 60rpx 0;
				> view:nth-child(1) {
					width: 172rpx;
					height: 172rpx;
					position: relative;
					margin: auto;
					box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.16);
					border-radius: 50%;
					border: 2rpx solid #ffffff;
					> image:nth-child(1) {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
					> view {
						width: 40rpx;
						height: 40rpx;
						background-color: #ffffff;
						position: absolute;
						right: 12rpx;
						bottom: 0;
						border-radius: 50%;
						display: flex;
						justify-content: center;
						align-items: center;
						> image {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}
				> view:last-child {
					width: 100%;
					margin-top: 32rpx;
					text-align: center;
					font-weight: 400;
					font-size: 32rpx;
					color: #333333;
				}
			}
			.operate-list {
				width: 688rpx;
				height: 210rpx;
				background: #ffffff;
				box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.1);
				border-radius: 20rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;
				padding: 0 20rpx;
				margin: auto;
				> view {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					flex: 1;
					height: 100%; /* Ensure full height */
					text-align: center;

					.icons {
						width: 78rpx;
						height: 78rpx;
						background: linear-gradient(146deg, #81b899 0%, #84c7a1 100%);
						box-shadow: 0rpx 0rpx 12rpx rgba(0, 118, 255, 0.1);
						border-radius: 50%;
						margin-bottom: 10rpx;
					}

					.titles {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}

				.contact {
					height: 100%; /* Make sure it takes full height */
					display: flex;
					align-items: center;
					justify-content: center;

					button {
						width: 100%;
						height: 100%;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						background: transparent;
						border: none;
						padding: 0;
						margin: 0;
						line-height: normal;

						&:after {
							border: none;
						}

						.icons {
							margin-bottom: 10rpx;

							image {
								width: 78rpx;
								height: 78rpx;
							}
						}

						.titles {
							font-family: PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #666666;
						}
					}
				}
			}
		}
	}

	.content-section {
		width: 100%;
		padding: 0 30rpx 0 32rpx;
		box-sizing: border-box;
		margin-top: 16rpx;
		&-list {
			background: #ffffff;
			box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.1);
			border-radius: 20rpx;
			padding: 0 12rpx 0 30rpx;
			box-sizing: border-box;
			> view {
				width: 100%;
				padding: 42rpx 0;
				display: flex;
				align-items: center;
				image {
					width: 32rpx;
					height: 32rpx;
				}
				text {
					margin-left: 20rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
				}
			}
			> view:nth-child(2) {
				border-top: 2rpx solid #eeeeee;
				border-bottom: 2rpx solid #eeeeee;
			}
		}
	}
}
</style>
